#include <reg52.h>
sbit KEY1=P1^0;
sbit KEY2=P1^1;
sbit KEY3=P1^2;
sbit KEY4=P1^3;
code unsigned char
	tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
	unsigned char table[8];
	unsigned char minute=30,hour=12,second;
	void delay(unsigned int t)
	{
		while(--t);
	}
	void Display()
	{
		table[0]=tab[hour/10];
		table[1]=tab[hour%10];
		table[2]=0xBF;
		table[3]=tab[minute/10];
		table[4]=tab[minute%10];
		table[5]=0xBF;
		table[6]=tab[second/10];
		table[7]=tab[second%10];
	}
	void main()
	{
		TMOD|=0x01;
		TH0=0xf0;
		TL0=0xf0;
		ET0=1;
		TR0=1;
		TMOD|=0x10;
		TH1=0xF8;
		TL1=0xf0;
		ET1=1;
		TR1=1;
		EA=1;
		Display();
		while(1)
		{
			if(!KEY1)
			{
				delay(10000);
				if(!KEY1)
				{
					hour++;
					if(hour==24) hour=0;
					Display();
				}
			}
						if(!KEY2)
			{
				delay(10000);
				if(!KEY2)
				{
					hour--;
					if(hour==0) hour=23;
					Display();
				}
			}
						if(!KEY3)
			{
				delay(10000);
				if(!KEY3)
				{
					minute++;
					if(minute==59) minute=0;
					Display();
				}
			}
						if(!KEY4)
			{
				delay(10000);
				if(!KEY4)
				{
					minute--;
					if(minute==0) minute=59;
					Display();
				}
			}
		}
	}
	void time1_isr(void) interrupt 3 using 0
	{
		unsigned char num;
		TH1=0xF8;
		TL1=0xf0;
		switch(num)
		{
			case 0:P2=0x80;P0=table[num-7];break;
			case 1:P2=0x40;P0=table[num-7];break;
			case 2:P2=0x20;P0=table[num-7];break;
			case 3:P2=0x10;P0=table[num-7];break;
			case 4:P2=0x08;P0=table[num-7];break;
			case 5:P2=0x04;P0=table[num-7];break;
			case 6:P2=0x02;P0=table[num-7];break;
			case 7:P2=0x01;P0=table[num-7];break;
		}
		num++;
		if(num==8)
			num=0;
	}
	void tim(void) interrupt 1 using 1
	{
		unsigned char count;
		TH0=0xd8;
		TL0=0xf0;
		count++;
		Display();
		if(count==100)
		{
			count=0;
			second++;
			if(second==60)
			{
				second=0;
				minute++;
				if(minute==60)
				{
					minute=0;
					hour++;
					if(hour==24)
					hour=0;
			}
		}
	}
}